<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>手机号码绑定</title>
    <base href="<?php echo base_url();?>" />
    <link href="style/base.css" rel="stylesheet" type="text/css" />
    <link href="style/common.css" rel="stylesheet" type="text/css" />
    <link href="style/houtai.css" rel="stylesheet" type="text/css" />
    <link href="style/my.css" rel="stylesheet" type="text/css" />
    <!-- <link href="uploadify/css/default.css" rel="stylesheet" type="text/css" /> -->
    <link href="uploadify/css/uploadify.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script src="js/organictabs.jquery.js"></script>
    <script type="text/javascript" src="js/Common.js"></script>
    <script type="text/javascript" src="js/Validation.js"></script>
    <script type="text/javascript" src="jscript/WdatePicker.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/jquery.blockUI.js"></script>
    <script type="text/javascript" src="uploadify/scripts/swfobject.js"></script>
    <script type="text/javascript" src="uploadify/scripts/jquery.uploadify.v2.1.0.min.js"></script>
<script type="text/javascript">
$(function(){
	$("#btnOK").bind("click",save);
	$("#btnGetCode").bind("click",getSmsCode);
	$("#btnCancel").bind("click",function(){
		$("#txtPhone,#txtPhoneNew,#txtCheckCode").val('');
		ClearError("txtPhone");
		ClearError("txtPhoneNew");
		ClearError("txtCheckCode");
	});
	$("#txtPhone").bind("blur",checkPhone);
	$("#txtPhoneNew").bind("blur",checkPhoneNew);
	$("#txtCheckCode").bind("blur",checkCode);
});
function save(){
	if(checkPhone()==false)
		return;
	if(checkPhoneNew()==false)
		return;
	if(checkCode()==false)
		return;
	//检测通过，保存新手机号码
	$.ajax({
		type:"post",
		url:"index.php/login/updateModifyPhone",
		dataType:"json",
		async:false,
		success:function(data){
			alert("修改成功");		
			$("#txtPhone,#txtPhoneNew,#txtCheckCode").val('');	
			ClearError("txtPhone");
			ClearError("txtPhoneNew");
			ClearError("txtCheckCode");
		}
	});
}

function getSmsCode(){
	$("#btnGetCode").unbind("click");
	if(checkPhone()==false){
		$("#btnGetCode").bind("click",getSmsCode);
		return;	
	}
	var params = {
				phone:$("#txtPhoneNew").val()
			};
	$.ajax({
		type:"post",
		url:"index.php/login/sendSmsForModify",
		dataType:"html",
		data:params,
		async:false,
		success:function(data){
			//$("#divTest").html(data);
		}
	});
	$("#btnGetCode").bind("click",getSmsCode);
	fun_timedown(300);
	return false;
}
function fun_timedown(time){
	$("#btnGetCode").hide();
    if(time=='undefined')
        time = 300;
    $("#spanSeconds").html("验证码已成功发送，"+time+"秒");
    
    time = time-1;
    if(time>=0)
    {
        setTimeout("fun_timedown("+time+")",1000);
    }else
    {
        //alert('倒计时结束啦');
        $("#btnGetCode").show();
        $("#spanSeconds").html('');
    }
}
function checkCode(){
	ClearError("txtCheckCode");
	var code = $("#txtCheckCode").val();
	var phone = $("#txtPhoneNew").val();
	if(IsEmpty(code)){
		SetError("txtCheckCode","请输入手机验证码");
		return false;
	}
	if(checkPhoneNew()==false)
		return false;
	var params = {
				phone:phone,
				code:code
			};
	var isok=true;
	$.ajax({
		type:"post",
		url:"index.php/login/checkModifyCode",
		dataType:"json",
		data:params,
		async:false,
		success:function(data){			
			if(data.ReturnCode!=1){
				SetError("txtCheckCode","验证码不符");
				isok=false;				
			}
		}
	});
	if(isok==false)
		return false;
	//验证通过
	SetOK("txtCheckCode");
	return true;
}
function checkPhone(){
	if(!$("#txtPhone")){
		return true;
	}
	var phone = $.trim($("#txtPhone").val());
	if(IsEmpty(phone)){
		SetError("txtPhone","请输入原手机号");
		return false;
	}
	if(!IsMobile(phone)){
		SetError("txtPhone","非有效手机号");
		return false;
	}
	var isok=true;
	var params = {phone:phone};
	$.ajax({
		type:"post",
		url:"index.php/login/checkPhoneForModify",
		dataType:"json",
		data:params,
		async:false,
		success:function(data){			
			if(data.ReturnCode==1){				
				SetError("txtPhone","不存在该手机号");
				isok=false;
			}
		}
	});
	if(isok==false)
		return false;
	SetOK("txtPhone");
	return true;
}
function checkPhoneNew(){	
	var phone = $.trim($("#txtPhoneNew").val());
	if(IsEmpty(phone)){
		SetError("txtPhoneNew","请输入新手机号");
		return false;
	}
	if(!IsMobile(phone)){
		SetError("txtPhoneNew","非有效手机号");
		return false;
	}
	if(phone == $.trim($("#txtPhone").val())){
		SetError("txtPhoneNew","新手机号和原手机号不能相同");
		return false;
	}
	var isok=true;
	var params = {phone:phone};
	$.ajax({
		type:"post",
		url:"index.php/login/checkPhoneForModify",
		dataType:"json",
		data:params,
		async:false,
		success:function(data){			
			if(data.ReturnCode!=1){				
				SetError("txtPhoneNew",data.Msg);
				isok=false;
			}
		}
	});
	if(isok==false)
		return false;
	SetOK("txtPhoneNew");
	return true;
}
</script>
</head>
<body>
<!-- head S-->
<?php
include 'header.php';
?>
<!-- head E-->

<div class="houtai_content mt_10 clearfix">
    <!-- 侧栏 开始 -->
    <?php
    include 'member_left.php';
    ?>
    <!-- 侧栏 结束 -->
    <div class="houtai_main">
        <div class="houtai_index">
            <div class="houtai_main_tit">用户中心&mdash;手机绑定</div>
	<form id="formCard">

		<!-- 手机邮箱 开始 -->

		<div class="youxiang">
<?php
if (! empty ( $user ['phone'] )) {
	$s1 = substr ( $user ['phone'], 0, 2 );
	$s2 = substr ( $user ['phone'], 9, 2 );
	print "<div class='youxiang_gs'>
				<img src='images/dh_d.jpg' width='18' height='18' /><span class='b'>绑定手机</span>
				<br />
				<img src='images/dh_x.jpg' width='16' height='16' /><span>已绑定手机号$s1********{$s2}，可使用手机号登录当前微博</span>
				<!--<input name='' type='image' src='images/gghm_inp.jpg' /> <input name='' type='image' src='images/ghtx_inp.jpg' /> -->
		</div>";
}

?>
 
 
 <div class="youxiang_sj">
				<img src="images/dh_d.jpg" width="18" height="18" /><span class="b">绑定手机</span>
 <?php
	if (! empty ( $user ['phone'] )) {
		print "<div class='youxian_k'>
			<div class='youxiang_span'><div class='right'>原手机号</div></div><input id='txtPhone' style='width:200px; height:25px;' type='text' />
			</div>
			<div class='youxian_k'>
			<div class='youxiang_wj'><a href='javascript:void(0)'>忘记手机号</a></div>
		</div>";
	}
	?>

 <div class="youxian_k">
					<div class="youxiang_span" style="width:200px;">
						<div class="right">所在地 &nbsp;&nbsp;&nbsp;&nbsp;<?php echo $user['provincename']."-".$user['cityname'];?></div>
					</div>

				</div>
				<div class="youxian_k">
					<div class="youxiang_span">
						<div class="right">新手机号</div>
					</div>
					<div class="pt_5">
						<input id="txtPhoneNew"
							style="width: 200px; height: 25px; vertical-align: middle"
							type="text" />
					</div>
				</div>
				<div class="youxian_k">
					<div class="youxiang_wj">
						<input id="chkAgree" type="checkbox" value="" /> 同意<a
							href="javascript:void(0)">《新浪微博手机增值服务条款》</a>
					</div>
				</div>
				<div class="youxian_k">
					<div class="youxiang_span">
						<div class="right">验证码</div>
					</div>
					<div class="pt_5" style="padding-left: 70px">
						<input id="txtCheckCode"
							style="width: 60px; height: 25px; vertical-align: middle;"
							type="text" /> <img id="btnGetCode" class="link"
							src="images/mianfei_inp.jpg" style="vertical-align: middle" /><span
							id="spanSeconds"></span>
					</div>
				</div>
				<div class="youxian_inp" style="padding: 30px 0px 30px 100px">
					<img id="btnOK" class="link" src="images/bdsj_inp.jpg" /> <img
						id="btnCancel" class="link" src="images/fq_inp.jpg" />
				</div>
			</div>
		</div>
		<!-- 手机邮箱 结束 -->


	</form>
            </div></div>
</div>
	<!-- 页脚 开始 -->
 <?php include 'footer.php';?>
<!-- 页脚 结束 -->
</body>
</html>
